package com.twd.netty;

import com.twd.handler.ChannelInit;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CharServer {
    // 服务绑定的本地端口
    private final int port;

    public CharServer(int port) {
        this.port = port;
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        System.out.println(new String(md5.digest("Growatt1234567".getBytes())));
    }

    // 启动服务
    public void start(){
        EventLoopGroup boss = new NioEventLoopGroup(1);
        EventLoopGroup worker = new NioEventLoopGroup();
        new ServerBootstrap()
                .group(boss, worker)
                .channel(NioServerSocketChannel.class)
                .childHandler(ChannelInit.INSTANCE)
                .bind(port);
    }
}
